<?php

namespace App\Repositories;

use App\Models\Project;
use Illuminate\Database\Eloquent\Model;

class ProjectRepository extends BaseRepository
{
	public function model()
	{
		return Project::class;
	}

	/**
	 * 获取公司的项目数据
	 *
	 * Date: 12/04/2018
	 * @author George
	 * @param $company
	 * @param bool $name
	 * @return $this
	 */
	public function getByCompany($company, $name = false)
	{
		$this->where('company_id', '=', $company);
		if ($name) {
			$this->where('name', 'like', "%{$name}%");
		}

		return $this;
	}

	/**
	 * 获取项目的询价设置
	 *
	 * Date: 01/05/2018
	 * @author George
	 * @param int $project_id
	 * @return \Illuminate\Database\Eloquent\Builder|Model|null|object
	 */
	public function getInspectionSetting(int $project_id)
	{
		return Project::query()->select(['id', 'name'])
			->with('circles:id,project_id')->where('id', $project_id)
			->withCount(['lines', 'circles', 'nodes'])->first();
	}

	protected function serialization(array $attributes)
	{
		// TODO: Implement serialization() method.
	}

}
